std::basic | 您所在的位置:网站首页 › string constructor › std::basic |
C++
Compiler support
Freestanding and hosted
Language
Standard library
Standard library headers
Named requirements
Feature test macros (C++20)
Language support library
Concepts library (C++20)
Metaprogramming library (C++11)
Diagnostics library
General utilities library
Strings library
Containers library
Iterators library
Ranges library (C++20)
Algorithms library
Numerics library
Localizations library
Input/output library
Filesystem library (C++17)
Regular expressions library (C++11)
Concurrency support library (C++11)
Technical specifications
Symbols index
External libraries
[edit] Strings library
Null-terminated strings
Byte strings
Multibyte strings
Wide strings
Classes
basic_string
basic_string_view(C++17)
char_traits
[edit] std::basic_string
Member functions
basic_string::basic_string
basic_string::~basic_string
basic_string::operator=
basic_string::assign
basic_string::assign_range(C++23)
basic_string::get_allocator
Element access
basic_string::at
basic_string::operator[]
basic_string::front(DR*)
basic_string::back(DR*)
basic_string::data
basic_string::c_str
basic_string::operator basic_string_view(C++17)
Iterators
basic_string::beginbasic_string::cbegin(C++11)
basic_string::endbasic_string::cend(C++11)
basic_string::rbeginbasic_string::crbegin(C++11)
basic_string::rendbasic_string::crend(C++11)
Capacity
basic_string::empty
basic_string::sizebasic_string::length
basic_string::max_size
basic_string::reserve
basic_string::capacity
basic_string::shrink_to_fit(DR*)
Modifiers
basic_string::clear
basic_string::insert
basic_string::insert_range(C++23)
basic_string::erase
basic_string::push_back
basic_string::pop_back(DR*)
basic_string::append
basic_string::append_range(C++23)
basic_string::operator+=
basic_string::replace
basic_string::replace_with_range(C++23)
basic_string::copy
basic_string::resize
basic_string::resize_and_overwrite(C++23)
basic_string::swap
Search
basic_string::find
basic_string::rfind
basic_string::find_first_of
basic_string::find_first_not_of
basic_string::find_last_of
basic_string::find_last_not_of
Operations
basic_string::compare
basic_string::starts_with(C++20)
basic_string::ends_with(C++20)
basic_string::contains(C++23)
basic_string::substr
Constants
basic_string::npos
Non-member functions
operator+
swap(std::basic_string)
erase(std::basic_string)erase_if(std::basic_string)(C++20)(C++20)
I/O
operator
getline
Comparison
operator==operator!=operatoroperator=operator(until C++20)(until C++20)(until C++20)(until C++20)(until C++20)(C++20)
Numeric conversions
stoistolstoll(C++11)(C++11)(C++11)
stoulstoull(C++11)(C++11)
stofstodstold(C++11)(C++11)(C++11)
to_string(C++11)
to_wstring(C++11)
Literals
operator""s(C++14)
Helper classes
hash(C++11)
Deduction guides (C++17)
[edit]
basic_string& assign( size_type count, CharT ch );
(1)
(constexpr since C++20)
basic_string& assign( const basic_string& str );
(2)
(constexpr since C++20)
(3)
basic_string& assign( const basic_string& str,
size_type pos, size_type count );
(until C++14)
basic_string& assign( const basic_string& str,
size_type pos, size_type count = npos);
(since C++14) (constexpr since C++20)
basic_string& assign( basic_string&& str ) noexcept(/* see below */);
(4)
(since C++11) (constexpr since C++20)
basic_string& assign( const CharT* s, size_type count );
(5)
(constexpr since C++20)
basic_string& assign( const CharT* s );
(6)
(constexpr since C++20)
template
basic_string& assign( InputIt first, InputIt last );
(7)
(constexpr since C++20)
basic_string& assign( std::initializer_list ilist );
(8)
(since C++11) (constexpr since C++20)
template
basic_string& assign( const StringViewLike& t );
(9)
(since C++17) (constexpr since C++20)
template
basic_string& assign( const StringViewLike& t, size_type pos, size_type count = npos); (10) (since C++17) (constexpr since C++20)Replaces the contents of the string. 1) Replaces the contents with count copies of character ch. 2) Replaces the contents with a copy of str. Equivalent to *this = str;. In particular, allocator propagation may take place.(since C++11) 3) Replaces the contents with a substring [pos, pos + count) of str. If the requested substring lasts past the end of the string, or if count == npos, the resulting substring is [pos, str.size()). If pos > str.size(), std::out_of_range is thrown. 4) Replaces the contents with those of str using move semantics. Equivalent to *this = std::move(str). In particular, allocator propagation may take place. 5) Replaces the contents with copies of the characters in the range [s, s + count). This range can contain null characters. 6) Replaces the contents with those of null-terminated character string pointed to by s. The length of the string is determined by the first null character using Traits::length(s). 7) Replaces the contents with copies of the characters in the range [first, last). This overload does not participate in overload resolution if InputIt does not satisfy LegacyInputIterator.(since C++11) 8) Replaces the contents with those of the initializer list ilist. 9) Implicitly converts t to a string view sv as if by std::basic_string_view sv = t;, then replaces the contents with those of sv, as if by assign(sv.data(), sv.size()). This overload participates in overload resolution only if std::is_convertible_v is true and std::is_convertible_v is false. 10) Implicitly converts t to a string view sv as if by std::basic_string_view sv = t;, then replaces the contents with the characters from the subview [pos, pos + count) of sv. If the requested subview lasts past the end of sv, or if count == npos, the resulting subview is [pos, sv.size()). If pos > sv.size(), std::out_of_range is thrown. This overload participates in overload resolution only if std::is_convertible_v is true and std::is_convertible_v is false. Contents 1 Parameters 2 Return value 3 Complexity 4 Exceptions 5 Example 6 Defect reports 7 See also [edit] Parameters count - size of the resulting string pos - index of the first character to take ch - value to initialize characters of the string with first, last - range to copy the characters from str - string to be used as source to initialize the characters with s - pointer to a character string to use as source to initialize the string with ilist - std::initializer_list to initialize the characters of the string with t - object (convertible to std::basic_string_view) to initialize the characters of the string with Type requirements -InputIt must meet the requirements of LegacyInputIterator. [edit] Return value*this [edit] Complexity 1) Linear in count. 2) Linear in size of str. 3) Linear in count. 4) Constant. If alloc is given and alloc != other.get_allocator(), then linear. 5) Linear in count. 6) Linear in size of s. 7) Linear in distance between first and last. 8) Linear in size of ilist. 9) Linear in size of t. [edit] Exceptions 4) noexcept specification: noexcept(std::allocator_traits::propagate_on_container_move_assignment::value || std::allocator_traits::is_always_equal::value)If the operation would result in size() > max_size(), throws std::length_error. If an exception is thrown for any reason, this function has no effect (strong exception safety guarantee). [edit] Example Run this code #include #include #include int main() { std::string s; // assign(size_type count, CharT ch) s.assign(4, '='); std::cout |
CopyRight 2018-2019 实验室设备网 版权所有 |